package arrayExercise.test4;

public class GirlFriendTest {
    public static void main(String[] args) {
        //1.定义数组存入女朋友的对象
        GirlFriend[] arr = new GirlFriend[4];
        //2.创建女朋友对象
        GirlFriend gf1 = new GirlFriend("小叶叶",17,"萌妹子","吃零食");
        GirlFriend gf2 = new GirlFriend("小包包",18,"美女","睡大觉");
        GirlFriend gf3 = new GirlFriend("小彩彩",19,"大美女","旅游");
        GirlFriend gf4 = new GirlFriend("小妮妮",20,"御妹","吃洋芋");
        //3.把对象添加到数组当中
        arr[0] = gf1;
        arr[1] = gf2;
        arr[2] = gf3;
        arr[3] = gf4;
        //4.求和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            sum += gf.getAge();
        }
        //5.求平均值
        int avg = sum/arr.length;

        //6.统计年龄比平均值低的有几个(统计思想)
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            //判断并打印
            if (arr[i].getAge() < avg){
                System.out.println(arr[i].getName()+", "+arr[i].getAge()+", "+arr[i].getGender()+", "+arr[i].getHobby());
                count++;
            }
        }
        System.out.println("年龄比平均年龄低的女朋友有 "+count+" 个");
    }
}
